using System.Globalization;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Razor;

var builder = WebApplication.CreateBuilder(args);

var supportedCultures = new[]
{
	new CultureInfo("en"),
	new CultureInfo("zh"),
};
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
   
	options.DefaultRequestCulture = new RequestCulture("en");
	options.SupportedCultures = supportedCultures;
	options.SupportedUICultures = supportedCultures;
	options.RequestCultureProviders = new List<IRequestCultureProvider>
	{
		//used to determine the culture information for a request based on information stored in a cookie.
		new CookieRequestCultureProvider()
	};
});
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddMvc()
	.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
	.AddDataAnnotationsLocalization();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
	app.UseExceptionHandler("/Home/Error");
	app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseRequestLocalization();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
		name: "default",
		pattern: "{controller=Home}/{action=Index}/{id?}")
	.WithStaticAssets();
app.Run();
